package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;
    @ApiOperation("护理等级管理分页查询")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> listAll(@ApiParam(value = "护理等级名称") String name,
                                                                @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
                                                                @ApiParam(value = "当前页码")
                                                                @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                                @ApiParam(value = "每页显示数量")
                                                                @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingLevelVo> result = nursingLevelService.getByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(result);
    }
    @PostMapping("/insert")
    @ApiOperation("添加护理等级")
    public ResponseResult insert(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.insert(nursingLevelDto);
        return ResponseResult.success();
    }
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult listAll(){
       List<NursingLevelVo> nursingPlanVoList =nursingLevelService.getAll();
       return ResponseResult.success(nursingPlanVoList);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult getById(@PathVariable Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }
    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingLevelService.deleteById(id);
        return ResponseResult.success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理等级状态")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status){
        nursingLevelService.updateStatus(id,status);
        return ResponseResult.success();
    }
}
